<?php

namespace app\common\model;

use think\Cache;
use think\Model;


class Article extends Model
{

    // 表名
    protected $name = 'article';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];

    /**
     * 获取最新公告
     */
    public static function getNotice()
    {
        $data = Cache::tag('api')->get('notice');
        if (!$data) {
            $data = self::where(['is_enable' => 1, 'category_id' => 19])->order('id DESC')->find();
            Cache::tag('api')->set('notice', $data, 60 * 60);
        }
        return $data;
    }

    /**
     * 根据ID获取文章详情
     */
    public function getDetail($id)
    {
        return self::where(['is_enable' => 1])->find($id);
    }
}
